<?php
declare(strict_types=1);

namespace App\Common\Modular\System\Command;

use App\Common\Modular\System\Serve\SeoServe;

use Core\Basics\BasicsCommand;

use Hyperf\Command\Annotation\Command;

use Symfony\Component\Console\Input\InputInterface;

use Symfony\Component\Console\Output\OutputInterface;

#[Command]
class ImpSeoCommand extends BasicsCommand
{

    /**
     * 执行的命令行
     *
     * @var null|string
     */
    protected ?string $name = 'app:seo-imp';


    public function __construct(string $name = null)
    {
        parent::__construct($name);
        $this->setDescription('把SEO注解更新到SEO中');
    }

    public function execute(InputInterface $input, OutputInterface $output): int
    {
        $choice = ['取消', '更新导入SEO注解', '更新导入SEO注解且删除已失效的SEO规则'];
        $handle = $this->choice('请选择操作', $choice, 0);
        switch ($handle) {
            case '更新导入SEO注解';
                if (container(SeoServe::class)->importSeoAnnotation()) {
                    $this->output->success('SEO规则已导入');
                } else {
                    $this->output->error('SEO规则导入失败');
                }
                break;
            case '更新导入SEO注解且删除已失效的SEO规则';
                if (container(SeoServe::class)->importSeoAnnotation(true)) {
                    $this->output->success('SEO规则已导入');
                } else {
                    $this->output->error('SEO规则导入失败');
                }
                break;
            case '取消';
                $this->output->warning('操作已取消');
                break;
        }
        return parent::execute($input, $output);
    }
}